package model

import (
	"github.com/quarkcloudio/quark-go/v2/pkg/dal/db"
	"github.com/wsl/hi-go/types"
	"gorm.io/gorm"
)

type Class struct {
	Id         int              `json:"id" gorm:"autoIncrement"`
	Name       string           `json:"name" gorm:"type:varchar(500)" binding:"required" form:"name" query:"name"`
	Status     int              `json:"status" gorm:"default:1"`
	StudentNum int              `json:"studentNum" binding:"required" form:"studentNum" query:"studentNum"`
	CreatedAt  *types.LocalTime `json:"created_at"`
	UpdatedAt  *types.LocalTime `json:"updated_at"`
	DeletedAt  gorm.DeletedAt   `json:"-"`
}

func (p *Class) Create(name string) error {
	class := Class{Name: name}
	dbErr := db.Client.Model(&p).Create(&class).Error
	return dbErr
}
